package com.logic.config.web.messageService;

import com.logic.comment.util.JwtUtils;
import com.logic.comment.util.RedisUtils;
import com.logic.config.netty.web.model.message.ActionBody;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@Slf4j
public class WSChanelService {
    /**
     * 通道key
     */
    public static final String CHANEL_USER_KEY = "chanel:%d:user";
    public static final String CHANEL_KEY = "channel";

    public static Integer chanelService(ActionBody actionBody, String sid) {
        Long playerId = JwtUtils.getPlayerId(sid);
        Map<String, Object> data = actionBody.getData();
        int i = (int) data.get(CHANEL_KEY);

        String key = String.format(CHANEL_USER_KEY,i);
        try {
            RedisUtils.redisUtils().hPut(key, playerId.toString(), sid, 60, TimeUnit.MINUTES);
        } catch (Exception e) {
            log.error("加入频道失败", e);
        }
        return i;
    }
}
